package com.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * DynamicMethodTest--bdqnPractice
 *
 * @author: Jovi
 * @createTime: 2017-08-02 13:38
 **/
public class DynamicMethodTest {

    public static void main(String[] args) {
        Class p = People.class;

        try {
            People pp = (People)p.newInstance();
            Method m1 = p.getDeclaredMethod("setName", String.class);
            Method m2 = p.getDeclaredMethod("setAge", int.class);

            m1.setAccessible(true);
            m2.setAccessible(true);
            m1.invoke(pp, "名字");
            m2.invoke(pp, 2);
            System.out.println(pp);
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
